package com.vpclub.view;

import org.springframework.web.servlet.View;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 *
 *      自定义视图
 *
 * @author : leimingchao
 * @date Date : 2021年07月31日 20:54
 */
public class MyView implements View {

    /**
     * 返回的数据的内容类型
     * @return
     */
    @Override
    public String getContentType() {
        return "text/html";
    }

    @Override
    public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("之前保存的数据：" + model);
        response.setContentType("text/html");
        List<String> vn = (List<String>) model.get("video");
        response.getWriter().write("哈哈<h1>即将展现精彩内容</h1>");
        vn.stream().forEach(item->{
            try {
                response.getWriter().write("<a>下载" + item + ".avi</a><br/>");
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        response.getWriter().write(""
        + "<script>" +
                "var aEle = document.getElementsByTagName('a');" +
                "aEle.onclick = function(){" +
                "alert('想下载吗？交学费')}"
                + "</script>");
    }
}
